#include <iostream>
#include <string>
#include <map>
using namespace std;

int main()
{
	string s;
	map<string, int> count;
	string elems[10] = { "H", "C", "N", "O", "Na", "Mg", "P", "S", "Cl", "K" };
	for (int i = 0; i < 10; ++i)
		count[elems[i]] = 0;
	cin >> s;

	int k = 1;
	int times;
	string name;

	string pos = "begin";

	for (int i = 0; i < s.length(); ++i)
	{
		if ((s[i] >= '1') && (s[i] <= '9'))
		{
			if ((pos=="begin")||(pos=="plus"))
				k = s[i] - '0';
			else
			{
				times = s[i] - '0';
				count[name] += k * times;
			}
			pos = "number";
		}
		else if (s[i] == '+')
		{
			if( (pos=="letter") )
				count[name] += k;
			k = 1;
			pos = "plus";
		}
		else
		{
			if ((s[i] == 'a') || (s[i] == 'g') || (s[i] == 'l'))
			{
				name += s[i];
			}
			else
			{
				if (pos == "letter")
				{
					count[name] += k;
				}
				name = s[i];
			}
			pos = "letter";
		}
	}
	if (pos == "letter")
	{
		count[name] += k;
	}

	for (auto elem : count)
	{
		if(elem.second>0)
			cout << elem.first << " " << elem.second << endl;
	}
}